<template>
  <div class="login">
    <el-card class="loginCard">
      <el-form
        :model="loginForm"
        status-icon
        :rules="loginRules"
        ref="loginFormRef"
        label-width="100px"
        class="loginForm"
      >
        <el-form-item label="账号" prop="username">
          <el-input type="text" v-model="loginForm.username"></el-input>
        </el-form-item>
        <el-form-item label="密码" prop="password">
          <el-input
            type="password"
            v-model="loginForm.password"
            autocomplete="off"
          ></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="submitForm()">登陆</el-button>
          <el-button @click="goRegister()">去注册</el-button>
        </el-form-item>
      </el-form>
    </el-card>
  </div>
</template>
<script>
export default {
  data() {
    return {
      //登录表单
      loginForm: {
        username: '',
        password: '',
      },
      //表单验证规则对象
      loginRules: {
        username: [
          { required: true, message: '请输入用户名', trigger: 'blur' },
        ],
        password: [{ required: true, message: '请输入密码', trigger: 'blur' }],
      },
      //注册表单
      registerForm: {},
    }
  },
  methods: {
    submitForm() {
      //async 异步
      this.$refs.loginFormRef.validate(async (valid) => {
        if (valid) {
          //await 简化promise操作
          //只拿到返回值中的data
          const { data: res } = await this.$axios.post('fgUser/sendLoginVerificationCode',this.loginForm);
          console.log(res);
          if (data.meta.status != 200) return this.$message.error("登陆失败");
          this.$message.success("登陆成功");
        } else {
          this.$message.warning("请检查用户名和密码是否合法");
          return false;
        }
      })
    },
    goRegister() {},
  },
}
</script>

<style lang="scss" scoped>
.login {
  display: flex;
  justify-content: center;
  align-items: center;
  .loginCard {
    width: 440px;
    height: 370px;
  }
}
</style>